package ccm.component.oscilloscope;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class TestDataManager extends OscilloscopeDataManager
{
    public TestDataManager()
    {
        super();
        add(1024*1024*8);
        Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::add,0,1,TimeUnit.MILLISECONDS);
    }

    private void add()
    {
        add(10);
    }

    private void add(int n)
    {
        for(int t=0;t<=n;++t)
        {
            final int i=getDataLength();
            float[] ans=new float[getDataColumn()-((i/10)%4)];
            ans[0]=Float.NaN;
            ans[1]=Float.POSITIVE_INFINITY;
            ans[2]=Float.NEGATIVE_INFINITY;
            for(int j=3;j<ans.length;++j)
            {
                ans[j]=(float)Math.sin(i*2e-3+j*2.0/getDataColumn()*Math.PI);
            }
            dataList.add(new TimeAndData((long)i*10*1000,ans));
        }
    }

    /**
     * 获取一共有几列
     *
     * @return 列数
     */
    @Override
    public int getDataColumn()
    {
        return 20;
    }
}
